<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <style></style>
  </head>
  <body>
    <div>
      <h1>减少声明及语句数</h1>
    </div>
    <div id="box" style="width: 100px; height: 100px"></div>
    <script>
      var oBox = document.getElementById("box");
      var test = (ele) => {
        let w = ele.offsetWidth;
        let h = ele.offsetHeight;
        return w + h;
      };

      //优化
      var test = (ele) => {
        return ele.offsetWidth + ele.offsetHeight;
      };

      test(oBox);

      //==
      var test = () => {
        var name = "xjq";
        var age = 22;
        var slogan = "123456";
        return name + age + slogan;
      };

      //优化
      var test = () => {
        var name = "xjq",
          age = 22,
          slogan = "123456";
        return name + age + slogan;
      };
      test();
    </script>
  </body>
</html>
